package com.example.demo.config;

import com.example.demo.common.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyConfig implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor).addPathPatterns("/**") //拦截所有的 url
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/user/reg")  //排除url /user/login 不拦截
                .excludePathPatterns("/image/**"); //排除 image 文件夹下的所有文件
    }
    //上述代码的意思就是将拦截器添加到系统配置项中
}
